package com.example.serviceaone.controller;

import com.example.serviceaone.apis.GetServiceC;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ATestController {
    @Resource
    private GetServiceC getServiceC;

    @RequestMapping(value = "/getAStr")
    //进行断路保护
    @CircuitBreaker(name = "ServiceC",fallbackMethod = "myCircuitFallback")
    public String getAStr(){
        String str = getServiceC.getCStr();
        return "学号：3221003139\n\n" + str;
    }

    // 服务降级处理，当服务熔断时，返回此结果
    public String myCircuitFallback(Exception ex){
        return "邓金玲您好：服务器出了点小差，请稍后再试~";
    }
}